﻿using System;
using System.Web.Routing;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using System.Web.Mvc;
using Super.Common;
using Super.Common.Validate;


namespace Super.DomainService
{
    public class ApplicationService
    {
        public static void Init()
        {
            StartTime = DateTime.Now;

            Log.GetUserName = () => SuperService.LoginUser.UserName;

            ApplicationAssembly = Assembly.GetCallingAssembly(); 

            //注册公共路由
            CommonController.RegisterCommonRoutes(RouteTable.Routes);

            
            //CacheService.GetCategory();//产品分类
     

        }

        private static void CheckController(IEnumerable<Type> types)
        {
            foreach (var item in types)
            {
                if (!typeof(CommonController).IsAssignableFrom(item) && typeof(Controller).IsAssignableFrom(item))
                {
                    throw new Exception(item.Name + " 必须从 CommonController 继承!\r\n  by 承志.");
                }
            }
        }

        /// <summary> 当前应用程序程序集信息.
        /// </summary>
        public static Assembly ApplicationAssembly
        { get; set; }

        /// <summary>应用程序启动时间
        /// </summary>
        public static DateTime StartTime
        {
            get;
            private set;
        }
    }
}
